package SecondeStage.IO.Reader_Writer;

import java.io.*;

public class BufferCopy {
    public static void main(String[] args) {
        // BufferedReader和BufferedWriter是按照字符操作的，不要去操作二进制文件，可能导致文件损坏
        String srcFilePath ="D:\\Java\\JavaProject\\hello.txt";
        String destFilePath = "D:\\Java\\JavaProject\\note.txt";
        BufferedReader br =null;
        BufferedWriter bw =null;
        String line;
        try {
            br = new BufferedReader(new FileReader(srcFilePath));
            bw = new BufferedWriter(new FileWriter(destFilePath));

            while ((line = br.readLine())!=null){
                // 每读取一行，就写入
                bw.write(line);
                // 插入一个换行符
                bw.newLine();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            // 关闭流

                try {
                    if(br!=null){
                        br.close();
                    }
                    if (bw!=null){
                        bw.close();
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

        }
    }
}
